﻿using DynamicViewFormApp.Setting;
using DynamicViewFormLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DynamicViewFormApp.Service
{
    class WorkSpaceService
    {
        /// <summary>
        /// Save Work Space
        /// </summary>
        internal bool SaveActivity()
        {
            bool isSuccess = true;
            RtfDomDocuments doc = new RtfDomDocuments();
            if (PaperSetting.Type != null)
            {
                string paperSize = PaperSetting.Type;
                switch (paperSize)
                {
                    case "A4":
                        doc.LoadTemplate(RtfContent.TemplateA4);
                        break;
                    case "A3":
                        doc.LoadTemplate(RtfContent.TemplateA3);
                        break;
                }
                doc.FormatTemplate(ExamInfo.ExamName);

                List<RichTextBox> rtbs = PageSetting.RichTextBoxeList;

                foreach (RichTextBox rtb in rtbs)
                {
                    rtb.SelectAll();
                    rtb.SelectionFont = FontSetting.FontFormat;
                    rtb.DeselectAll();
                    string rtfText = rtb.Rtf;
                    doc.Append(rtb.Rtf);
                }

                doc.SaveActivity(ExamInfo.ExamName + "_" + paperSize);
            }
            else
            {
                isSuccess = false;
            }
            return isSuccess;
        }
    }
}
